import java.awt.*;
import java.awt.event.*;
import java.io.*;

import javax.swing.*;


public class Player extends Rectangle implements ActionListener {
	private ImageIcon[] up,down,left,right;
	private int phase,lives,spd,power,numBomb,counter;
	private boolean walkOver;
	private String whichDir;
	private Timer t, invul;
	public Player(String p,int x, int y,String wD){
		this.x = x;
		this.y = y;
		whichDir = wD;
		spd = 5;
		counter =0;
		walkOver = false;
		numBomb = 1;
		power = 2;
		up = new ImageIcon[]{new ImageIcon(p+"/up1.gif"),new ImageIcon(p+"/up2.gif"),new ImageIcon(p+"/up3.gif")};
		left = new ImageIcon[]{new ImageIcon(p+"/left1.gif"),new ImageIcon(p+"/left2.gif"),new ImageIcon(p+"/left3.gif")};
		right = new ImageIcon[]{new ImageIcon(p+"/right1.gif"),new ImageIcon(p+"/right2.gif"),new ImageIcon(p+"/right3.gif")};
		down = new ImageIcon[]{new ImageIcon(p+"/down1.gif"),new ImageIcon(p+"/down2.gif"),new ImageIcon(p+"/down3.gif")};
		lives = 3;
		phase = 0;
		invul = new Timer(100,this);
		t = new Timer(100,this);
		t.start();
	}

	public void actionPerformed(ActionEvent e) {
		phase++;      //not swag
	}
	public ImageIcon move(String dir){
		if (dir.equals("up")){
			up();
			whichDir = "u";
			return up[phase%3];
		}
		else if (dir.equals("down")){
			down();
			whichDir = "d";
			return down[phase%3];
		}
		else if (dir.equals("right")){
			right();
			whichDir = "r";
			return right[phase%3];
		}
		else if (dir.equals("left")){
			left();
			whichDir = "l";	
			return left[phase%3];
		}
		else{
			if (whichDir.equals("r"))
				return right[0];
			else if (whichDir.equals("l"))
				return left[2];
			else if (whichDir.equals("u"))
				return up[1];
			return down[1];
		}
	}
	private void right(){
		x+=spd;
	}
	private void up(){
		y-=spd;
	}
	private void left(){
		x-=spd;
	}
	private void down(){
		y+=spd;
	}
	public int getPow(){
		return power;
	}
	public int totalBomb(){
		return numBomb;
	}
}
